package Server.ServerCore.Controller;

import Server.ServerCore.Model.Player.PlayerInstance;
import Server.ServerCore.Service.DataPacks.packRequest.point_requst;
import Server.ServerCore.Service.Logic.HandleController;
import Server.ServerCore.Service.Logic.RegisterPack;
import Server.ServerCore.Service.service.PlayerManagerService;
import org.jboss.netty.buffer.ChannelBuffer;
import org.springframework.stereotype.Service;
/**
 * @author :石头哥哥<br/>
 *         Project:21Server
 *         Date: 13-4-13
 *         Time: 下午12:20
 *         PointsController=213
 */
@Service
public class PointsController extends HandleController {
    private static final long serialVersionUID = -2543282624257115445L;

    /**
     * 数据分解具体处理的函数
     *
     * @param buffer buffer
     * @param player player
     */
    @Override
    public void DispatchPack(ChannelBuffer buffer, PlayerInstance player) throws Exception {
        point_requst pointRequst= (point_requst) parseObject(buffer,point_requst.class);
        int points=pointRequst.getPoints();

        int serverPoints= PlayerManagerService.getPlayerPoints(player,pointRequst.getCircleUnitID());

        if (points==serverPoints&&pointRequst.getCircleUnitID()!=-1){
            if (player.getCircleUnitIDS().contains(pointRequst.getCircleUnitID()))
                player.getDeckoOfCardsVOFastList()[pointRequst.getCircleUnitID()].setPoints(points);
        }
    }

    /**
     * 通过spring产生处理数据的controller，储存在数组中
     */
    @Override
    public void InitiController() {
        RegisterPack.GAME_CONTROLLERS[213]=this;
    }
}
